﻿using Decoration.IRepository;
using Decoration.IService;
using Decoration.Models.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Decoration.Service
{
    public class MenuInfoService : BaseService<Base_MenuInfo>, IMenuInfoService
    {
        IMenuInfoRepository _rep;

        public MenuInfoService(IMenuInfoRepository rep, IBaseQueryRepository brep) : base(rep, brep)
        {
            _rep = rep;
        }

        public IEnumerable<Base_MenuInfo> GetMenuByUserId(int UserId)
        {
            var sql = @"  select distinct mi.* from Base_UserRoles ur
                    inner join Base_RoleMenus rm on ur.RoleId=rm.RoleId
                    inner join Base_MenuInfos mi on rm.MenuId=mi.Id
                    where UserId=1 and mi.Status=1 and mi.isshow=1
                    ";
            var list = Query<Base_MenuInfo>(sql, new { UserId });
            return list;
        }
        public IEnumerable<Base_MenuInfo> MenuOne()
        {
            var sql = @" select * from Base_MenuInfos where PId=0 and Status=1 order by MenuOrder ";

            var list = Query<Base_MenuInfo>(sql);
            return list;
        }
    }
}
